package cn.cmcc.online.smsapi.ui.util;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;

public class ContentUtil {
    public static final String NO_DATA = "--";
    public static final String NO_DATE = "--月--日";
    public static final String NO_TIME = "--:--";
    public static final String NO_CITY = "选择到达站";

    public static void setViewVisibility(View view, int visibility) {
        if (view != null) {
            view.setVisibility(visibility);

        }
    }

    public static Drawable setDrawableColorFilter(Drawable dw, String color) {
        try {
            if (dw == null || color == null || color.trim().length() == 0) {
                return null;
            }
            dw.mutate();
            dw.setColorFilter(Color.parseColor(color), PorterDuff.Mode.SRC_ATOP);
            return dw;
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;
    }

    public static int indexOfChild(View view, ViewGroup apView, int id) {
        if (view == null || apView == null) {
            return -1;
        }
        int childCount = apView.getChildCount();
        View child ,tempChild;
        for (int i = 0; i < childCount; i++) {
            child = apView.getChildAt(i);
            if (child == view) {
                return i;
            } else {
                tempChild = child.findViewById(id);
                if (tempChild == null) {
                    continue;
                }
                if (tempChild == view) {
                    return i;
                }
            }
        }
        return -1;
    }
}
